#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "facerecognizerstrategy.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_timer = new QTimer(this);
    m_recognizer = new Recognizer();
}

MainWindow::~MainWindow()
{
    delete m_recognizer;
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    /*Mat edges;
    for(;;)
    {
        Mat frame;
        cap>>frame;
        cvtColor(frame,edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges,Size(7,7),1.5,1.5);
        Canny(edges, edges,0,90,3);
        imshow("qq",edges);
        int c=waitKey(33);
        if(c==27)  break;
    }*/
    if (!m_recognizer->openCamera())
        qDebug("fuck");
    else
    {
        connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
        m_timer->start(33);
    }
}


void MainWindow::on_pushButton_2_clicked()
{
    m_recognizer->closeCamera();
    m_timer->stop();
    disconnect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
}

void MainWindow::onTimeout()
{
    ui->label->setPixmap(QPixmap::fromImage(Mat2QImage::ConvertToQImage(m_recognizer->getFrame(0.5))));
    ui->label->resize(ui->label->pixmap()->size());
}

void MainWindow::on_pushButton_3_clicked()
{
    m_recognizer->setRecognizerStrategy(new FaceRecognizerStrategy());
}
